#include "../../server/ExchangeManager.hpp"
#include <google/protobuf/map.h>
#include <gtest/gtest.h>
#include <unordered_map>
#include <string>

micromq::ExchangeManager::ptr emp;

class ExchangeTest : public testing::Environment
{
public:
    virtual void SetUp() override
    {
        emp = std::make_shared<micromq::ExchangeManager>("./meta.db");
    }

    virtual void TearDown() override
    {
        // emp->clear();
    }
};

TEST(exchange_test, insert_test)
{
    // google::protobuf::Map<std::string, std::string> testMap = {{"k1", "v1"}, {"k2", "v2"}};
    google::protobuf::Map<std::string, std::string> testMap;
    emp->declareExchange("e1", micromq::ExchangeType::DIRECT, true, false, testMap);
    emp->declareExchange("e2", micromq::ExchangeType::DIRECT, true, false, testMap);
    emp->declareExchange("e3", micromq::ExchangeType::DIRECT, true, false, testMap);
    ASSERT_EQ(emp->size(), 3);
}

TEST(exchange_test, select_test)
{
    micromq::Exchange::ptr exp = emp->getExchange("e1");
    ASSERT_NE(exp.get(), nullptr);
    ASSERT_EQ(exp->_name, "e1");
    ASSERT_EQ(exp->_type, micromq::ExchangeType::DIRECT);
    ASSERT_EQ(exp->_durable, true);
    ASSERT_EQ(exp->_autoDelete, false);
}

TEST(exchange_test, delete_test)
{
    emp->removeExchange("e3");
    micromq::Exchange::ptr exp = emp->getExchange("e3");
    ASSERT_EQ(exp.get(), nullptr);
    ASSERT_EQ(emp->isExists("e3"), false);
}

int main(int argc, char* argv[])
{
    testing::InitGoogleTest(&argc, argv);
    testing::AddGlobalTestEnvironment(new ExchangeTest);
    RUN_ALL_TESTS();

    return 0;
}